# !usr/bin/env python
# -*-coding:utf-8 -*-

# @FileName: emit_log.py
# @Author:tian
# @Time:06/22/2021

import pika

credentials = pika.PlainCredentials('rain','8800')
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',
                                                               port='5672',
                                                               virtual_host='/',
                                                               credentials=credentials))
# 建立rabbit协议的通道
channel = connection.channel()
# fanout: 所有绑定到此exchange的queue都可以接收消息(实时广播)
# direct: 通过routingKey和exchange决定的那一组的queue可以接收消息(有选择接受)
# topic： 所有符合routingKey(此时可以是一个表达式)的routingKey所bind的queue可以接收消息(更细致的过滤)
channel.exchange_declare('logs',exchange_type='fanout')
msg = 'this is java - {}'
for i in range(50):
    channel.basic_publish(exchange='logs',routing_key='',body=msg.format(i))

connection.close()
